<!-- 从业者-填报证书 -->
<template>
	<view class="container">
		<!-- picker弹窗 -->
		<u-picker v-model="show" :mode="mode" :range="range" @confirm="confirm"></u-picker>

		<!-- 表单区域 -->
		<view class="form-container">
			<u-form :model="form" ref="form" :rules="rules">
				<!-- 报考城市 -->
				<u-field v-model="form.companyName" label="报考城市：" label-width="160" prop="companyName" placeholder="请输入报考的城市"
					:placeholder-style="placeholderStyle">
				</u-field>

				<!-- 报考等级 -->
				<u-field v-model="form.businessType" label="报考等级：" label-width="160" prop="companyName" placeholder="请选择报考等级"
					:placeholder-style="placeholderStyle" @click="isShowPicker(0)">
				</u-field>

				<!-- 固定分类 -->
				<u-field v-model="form.businessStatus" label="鉴定分类：" label-width="160" placeholder="请选择企业鉴定分类"
					:placeholder-style="placeholderStyle" @click="isShowPicker(1)">
				</u-field>

				<view class="checkbox-container">
					<text style="font-size: 16px; line-height: 32px;">是否参加培训</text>
					<u-checkbox-group>
						<u-checkbox v-model="boxchecked" :disabled="false" shape="circle">参加</u-checkbox>
					</u-checkbox-group>
				</view>
			</u-form>
			
			<view class="text-container">
				<text style="font-size: 16px; line-height: 32px;">含培训费：￥123.00</text>
				<text style="font-size: 16px; line-height: 32px;">福利赠送：（报名成功后可学习）</text>
				<text style="font-size: 16px; line-height: 32px;">1、在线课程-XXXXXXXXXX课程名称</text>
				<text style="font-size: 16px; line-height: 32px;">2、练习题库-XXXXX名称</text>				
			</view>

			<!-- 按钮组 -->
			<view class="button-group">
<!-- 				<u-button type="default" @click="handlePrev" shape="circle" :custom-style="customStyleObject">
					上一步
				</u-button> -->
				<u-button type="primary" @click="handleSubmit" shape="circle" :loading="loading">
					提交
				</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				boxchecked: false,
				loading: false,
				clearable: false,
				// showBusinessTypePicker: false,
				// showAddressPicker: false,
				doorPhotos: [],
				// 步骤条
				stepsList: [{
						name: "手机号"
					},
					{
						name: "营业执照"
					},
					{
						name: "企业信息"
					}
				],
				// 弹出窗口内容
				show: false,
				mode: "selector",
				range: ['有限责任公司', '股份有限公司', '个体工商户', '其他'],
				NumberValue: 0,
				// field控件的样式
				placeholderStyle: "color:#bcbcbc",
				required: true,
				// 按钮组中的样式写法
				customStyleObject: {
					marginRight: '20rpx'
				},
				


				form: {
					companyName: '福州',
					businessType: '',
					businessStatus: '营业中',
					businessAddress: '',
					detailAddress: ''
				},
				// 企业介绍输入框
				introduction: '',
				currentCount: 0,
				maxCount: 1000,
				// 验证
				rules: {
					companyName: [{
						required: true,
						message: '请输入企业名称',
						trigger: 'blur'
					}]
				}
			}
		},
		methods: {
			// 门头照上传
			afterDoorPhotoRead(event) {
				this.doorPhotos = event.file;
			},
			deleteDoorPhoto(index) {
				this.doorPhotos.splice(index, 1);
			},

			// 显示经营类型弹窗
			isShowPicker(value) {
				if (value == 0) {
					this.NumberValue = value;
					this.mode = "selector";
					this.range = ['有限责任公司', '股份有限公司', '个体工商户', '其他'];
					this.defaultSelector = [0];
				} else if (value == 1) {
					this.NumberValue = value;
					this.mode = "selector";
					this.range = ['营业中', '暂停营业'];
					this.defaultSelector = [0];
				} else {
					this.NumberValue = value;
					this.mode = "region"
					// this.range = [['亚洲', '欧洲'], ['中国', '日本'], ['北京', '上海', '广州']];
					// this.defaultSelector = [0, 0, 0];
				}
				this.show = true
			},

			// 计算企业介绍内字数
			handleInput() {
				// 计算当前字数（考虑中文和符号）
				this.currentCount = this.introduction.length

				// 如果超过最大字数，截取前1000个字符
				if (this.currentCount > this.maxCount) {
					this.introduction = this.introduction.substring(0, this.maxCount)
					this.currentCount = this.maxCount
				}
			},

			// 选择确认
			confirm(e) {
				if (this.NumberValue == 0) {
					this.form.businessType = this.range[e[0]];
				} else if (this.NumberValue == 1) {
					this.form.businessStatus = this.range[e[0]];
				} else {
					this.form.businessAddress = e.province.label + '-' + e.city.label + '-' + e.area.label;;
				}
			},

			// 经营类型选择
			confirmBusinessType(e) {
				this.form.businessType = e.value[0].label;
				this.showBusinessTypePicker = false;
			},

			// 地址选择
			confirmAddress(e) {
				const [province, city, district] = e.value;
				this.form.businessAddress = `${province.name}-${city.name}-${district.name}`;
				this.showAddressPicker = false;
			},

			// 上一步
			handlePrev() {
				uni.navigateBack();
			},

			// 提交
			handleSubmit() {
				uni.navigateTo({
					url: '/pages/Practitioner/instiVisitPract/instiVisitFinish'
				})
				this.$refs.form.validate(valid => {
					if (!valid) return;
					this.loading = true;
					// uni.navigateTo({
					// 	url: '/pages/Practitioner/instiVisitPract/instiVisitFinish'
					// })

					// 模拟API调用
					// setTimeout(() => {
					// 	this.loading = false;
					// 	uni.showToast({
					// 		title: '提交成功',
					// 		icon: 'success',
					// 		complete: () => {
					// 			uni.navigateTo({
					// 				url: '/pages/register/register-finish'
					// 			});
					// 		}
					// 	});
					// }, 1500);
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 10rpx;
		// background-color: #f5f5f5;
		min-height: 100vh;

		.required {
			color: #f56c6c;
		}

		/deep/ .u-steps {
			background: #fff;
			padding: 30rpx;
			border-radius: 12rpx;
			margin-bottom: 30rpx;
		}

		.introduction {
			padding: 10px 0rpx;
			background-color: #fff;

			.header {
				margin-bottom: 10rpx;
				display: flex;

				.title {
					// font-size: 36rpx;
					// font-weight: bold;
					color: #333;
				}
			}

			.textarea-container {
				position: relative;

				/deep/ .u-input__textarea {
					padding: 20rpx;
					background-color: #f5f5f5;
					border-radius: 10rpx;
					font-size: 28rpx;
				}

				.word-count {
					position: absolute;
					right: 20rpx;
					bottom: 20rpx;
					font-size: 24rpx;
					color: #999;
					background-color: rgba(245, 245, 245, 0.7);
					padding: 0 10rpx;
					border-radius: 4rpx;
				}
			}
		}


		.form-container {
			background: #fff;
			padding: 20rpx;
			border-radius: 12rpx;

			/deep/ .u-field {
				padding: 10px 0;
			}

			/deep/ .u-form-item__label {
				.required {
					color: #f56c6c;
					margin-right: 4rpx;
				}
			}

			.upload-section {
				margin-bottom: 40rpx;

				.upload-title {
					font-size: 28rpx;
					color: #606266;
					margin-bottom: 16rpx;
					display: block;

				}
			}
			
			// 选择是否参加
			.checkbox-container {
				display: flex;
				justify-content: space-between;
				margin: 20rpx 0;
				line-height: 16px;
			}	
			
			
			.text-container {
				background-color: #e7ebf3;
				border-radius: 12rpx;
				display: flex;
		    flex-direction: column;
				padding: 20rpx;
				font-size: 8px;
			}

			.button-group {
				display: flex;
				justify-content: space-between;
				margin-top: 60rpx;

				// 此样式主要为了适配wx小程序的按钮
				/deep/ .u-size-default {
					width: 350px;
				}

				.u-btn {
					flex: 1;
				}
			}
		}
	}
</style>